<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance(); 
	$teamDataArray = $ci->team_entity->getArrayIdAndNameOfTeam();	
	$TOURNAMENT = $ci->tournament_entity->init('id',$tournament_id);
	$sportDataArray = $ci->sport_entity->getArrayIdAndNameOfSport();	
?>
<?php if(!isset($id)): ?>
<form action="<?php echo site_url('admin/dataman/match/match_submit');?>" name="match_submit" id="match_submit" method="post" enctype="multipart/form-data" >
	<input type="hidden" name="tournament_id" id="tournament_id" value="<?php echo $TOURNAMENT->getId();?>" />
	<input type="hidden" name="feed_type" id="feed_type" value="" />
	<input type="hidden" name="feed_key" id="feed_key" value="" />
	<input type="hidden" name="feed_match_id" id="feed_match_id" value="" />
	<input type="hidden" name="feed_category_id" id="feed_category_id" value="" />
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Match Title:</span></div>
	<div class="grid6"><input type="text" maxlength="500" id="title" name="title" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="title_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Home Match:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'home',
								$options = $teamDataArray,
								$selected = array(),
								"id='home'"
							);	?></div>
	<div class="grid2"><span class="bold red hidden" id="home_error">Required field.</span></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Score:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_score" name="home_score" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_score_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Wickets:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_wickets" name="home_wickets" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_wickets_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Overs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_overs" name="home_overs" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_overs_error">Required field.</span></div>
	<div class="clrboth"></div>
<!--	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Home Runs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_runs" name="home_runs" value="0" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_runs_error">Required field.</span></div>
	<div class="clrboth"></div>
-->	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Away Match:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'away',
								$options = $teamDataArray,
								$selected = array(),
								"id='away'"
							);	?></div>	
	<div class="grid2"><span class="bold red hidden" id="away_error">Required field.</span></div>						
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Score:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_score" name="away_score" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_score_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Wickets:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_wickets" name="away_wickets" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_wickets_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Overs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_overs" name="away_overs" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_overs_error">Required field.</span></div>
	<div class="clrboth"></div>
<!--	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Away Runs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_runs" name="away_runs" value="0" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_runs_error">Required field.</span></div>
	<div class="clrboth"></div>
-->
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Result:</span></div>
	<div class="grid6"><input type="text" maxlength="255" id="result" name="result" value="" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="result_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Start time:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="start_time" name="start_time" value="" class="std-input"/>
		<button id="start_time_btn">choose</button>
		<br/> <i>&nbsp; > <?php echo sysDateTimeFormat($TOURNAMENT->getStartTime());?></i>
	</div>
	<div class="grid2"><span class="bold red hidden" id="start_time_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*End time:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="end_time" name="end_time" value="" class="std-input"/>
		<button id="end_time_btn">choose</button>
		<br/> <i>&nbsp; < <?php echo sysDateTimeFormat($TOURNAMENT->getEndTime());?></i>
	</div>
	<div class="grid2"><span class="bold red hidden" id="end_time_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Sport:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'sport_id',
								$options = $sportDataArray,
								$selected = array(),
								"id='sport_id'"
							);	?></div>	
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Convertion rate:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="convertion_rate" name="convertion_rate" value="100:25" /> points:coins
	</div>
	<div class="grid2"><span class="bold red hidden" id="convertion_rate_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">Enable Convertion:</span></div>
	<div class="grid6">
		<input type="checkbox" id="convertion_enable" name="convertion_enable" value="yes" /> 
	</div>
	<div class="grid2"><span class="bold red hidden" id="convertion_rate_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">Use default Events:</span></div>
	<div class="grid6">
		<input type="checkbox" id="use_default_event" name="use_default_event" value="yes" checked="checked" /> 
	</div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">Email notify enable:</span></div>
	<div class="grid6">
		<input type="checkbox" id="email_notify_enable" name="email_notify_enable" value="yes" checked="checked" /> 
	</div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">SMS notify enable:</span></div>
	<div class="grid6">
		<input type="checkbox" id="sms_notify_enable" name="sms_notify_enable" value="yes" checked="checked" /> 
	</div>
	<div class="clrboth"></div>
	
	<div class="grid2">&nbsp;</div>
	<div class="grid6"><input type="submit" class="button" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
	<div class="clrboth"></div>	
	
</form>
<?php else:?>
<form action="<?php echo site_url('admin/dataman/match/match_submit');?>" name="match_submit" id="match_submit" method="post" enctype="multipart/form-data" >
	<input type="hidden" name="tournament_id" id="tournament_id" value="<?php echo $TOURNAMENT->getId();?>" />
	<?php $MATCH = $ci->match_entity->init('id',$id);?>
	
	<input type="hidden" name="feed_type" id="feed_type" value="<?php echo $MATCH->getFeedType();?>" />
	<input type="hidden" name="feed_key" id="feed_key" value="<?php echo $MATCH->getFeedKey();?>" />
	<input type="hidden" name="feed_match_id" id="feed_match_id" value="<?php echo $MATCH->getFeedMatchId();?>" />
	<input type="hidden" name="feed_category_id" id="feed_category_id" value="<?php echo $MATCH->getFeedCategoryId();?>" />
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Match Title:</span></div>
	<div class="grid6"><input type="text" maxlength="500" id="title" name="title" value="<?php echo $MATCH->getTitle();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="title_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Home Match:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'home',
								$options = $teamDataArray,
								$selected = array($MATCH->getHome()),
								"id='home'"
							);	?></div>
	<div class="grid2"><span class="bold red hidden" id="home_error">Required field.</span></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Score:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_score" name="home_score" value="<?php echo $MATCH->getHomeScore();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_score_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Wickets:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_wickets" name="home_wickets" value="<?php echo $MATCH->getHomeWickets();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_wickets_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Home Overs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_overs" name="home_overs" value="<?php echo $MATCH->getHomeOvers();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_overs_error">Required field.</span></div>
	<div class="clrboth"></div>
<!--	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Home Runs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="home_runs" name="home_runs" value="<?php /* echo $MATCH->getHomeRuns();*/ ?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="home_runs_error">Required field.</span></div>
	<div class="clrboth"></div>
-->	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Away Match:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'away',
								$options = $teamDataArray,
								$selected = array($MATCH->getAway()),
								"id='away'"
							);	?></div>	
	<div class="grid2"><span class="bold red hidden" id="away_error">Required field.</span></div>						
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Score:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_score" name="away_score" value="<?php echo $MATCH->getAwayScore();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_score_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Wickets:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_wickets" name="away_wickets" value="<?php echo $MATCH->getAwayWickets();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_wickets_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Away Overs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_overs" name="away_overs" value="<?php echo $MATCH->getAwayOvers();?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_overs_error">Required field.</span></div>
	<div class="clrboth"></div>
<!--	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">*Away Runs:</span></div>
	<div class="grid6"><input type="text" maxlength="5" id="away_runs" name="away_runs" value="<?php /* echo $MATCH->getAwayRuns();*/ ?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="away_runs_error">Required field.</span></div>
	<div class="clrboth"></div>
-->	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Result:</span></div>
	<div class="grid6"><input type="text" maxlength="255" id="result" name="result" value="<?php echo $MATCH->getResult(); ?>" class="std-input"/></div>
	<div class="grid2"><span class="bold red hidden" id="result_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Start time:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="start_time" name="start_time" value="<?php echo sysDateTimeFormat($MATCH->getStartTime()); ?>" class="std-input"/>
		<button id="start_time_btn">choose</button>
		<br/> <i>&nbsp; > <?php echo sysDateTimeFormat($TOURNAMENT->getStartTime());?></i>
		</div>
	<div class="grid2"><span class="bold red hidden" id="start_time_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*End time:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="end_time" name="end_time" value="<?php echo sysDateTimeFormat($MATCH->getEndTime()); ?>" class="std-input"/>
		<button id="end_time_btn">choose</button>
		<br/> <i>&nbsp; < <?php echo sysDateTimeFormat($TOURNAMENT->getEndTime());?></i>
	</div>
	<div class="grid2"><span class="bold red hidden" id="end_time_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="clrboth"></div>
	<div class="grid2"><span class="bold">Sport:</span></div>
	<div class="grid6"><?php echo form_dropdown( 'sport_id',
								$options = $sportDataArray,
								$selected = array($MATCH->getSportId()),
								"id='sport_id'"
							);	?></div>
							
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">*Convertion rate:</span></div>
	<div class="grid6">
		<input type="text" maxlength="255" id="convertion_rate" name="convertion_rate" value="<?php echo $MATCH->getConvertionRate(); ?>" /> points:coins
	</div>
	<div class="grid2"><span class="bold red hidden" id="convertion_rate_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<?php 
		$convertionCheck = $MATCH->getEnableConvertion() == 'yes' ? "checked='checked'" : ""; 
		$emailNotifyCheck = $MATCH->getEmailNotifyEnable() == 'yes' ? "checked='checked'" : ""; 
		$smsNotifyCheck = $MATCH->getSmsNotifyEnable() == 'yes' ? "checked='checked'" : "";
	?>
	
	<div class="grid2"><span class="bold">Enable Convertion:</span></div>
	<div class="grid6">
		<input type="checkbox" id="convertion_enable" name="convertion_enable" value="yes" <?php echo $convertionCheck;?> />
	</div>
	<div class="grid2"><span class="bold red hidden" id="convertion_rate_error">Required field.</span></div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">Use default Events:</span></div>
	<div class="grid6">
		<input type="checkbox" id="use_default_event" name="use_default_event" value="yes" /> 
	</div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">Email notify enable:</span></div>
	<div class="grid6">
		<input type="checkbox" id="email_notify_enable" name="email_notify_enable" value="yes" <?php echo $emailNotifyCheck;?> /> 
	</div>
	<div class="clrboth"></div>
	
	<div class="grid2"><span class="bold">SMS notify enable:</span></div>
	<div class="grid6">
		<input type="checkbox" id="sms_notify_enable" name="sms_notify_enable" value="yes" <?php echo $emailNotifyCheck;?> /> 
	</div>
	<div class="clrboth"></div>
	
	<input type="hidden" name="id" id="id" value="<?php echo $id;?>" />
	
	<div class="grid2">&nbsp;</div>
	<div class="grid6"><input type="submit" class="button" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
	<div class="clrboth"></div>		
	
</form>
<?php endif;?>